home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_400 / 414_01 / comm2.c < prev    next >
C/C++ Source or Header  |  1993-11-23  |  34KB  |  1,157 lines

  1. /***********************************************************************/
  2. /* COMM2.C - Commands E-J                                              */
  3. /* This file contains all commands that can be assigned to function    */
  4. /* keys or typed on the command line.                                  */
  5. /***********************************************************************/
  6. /*
  7.  * THE - The Hessling Editor. A text editor similar to VM/CMS xedit.
  8.  * Copyright (C) 1991-1993 Mark Hessling
  9.  *
  10.  * This program is free software; you can redistribute it and/or
  11.  * modify it under the terms of the GNU General Public License as
  12.  * published by the Free Software Foundation; either version 2 of
  13.  * the License, or any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  18.  * General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to:
  22.  *
  23.  *    The Free Software Foundation, Inc.
  24.  *    675 Mass Ave,
  25.  *    Cambridge, MA 02139 USA.
  26.  *
  27.  *
  28.  * If you make modifications to this software that you feel increases
  29.  * it usefulness for the rest of the community, please email the
  30.  * changes, enhancements, bug fixes as well as any and all ideas to me.
  31.  * This software is going to be maintained and enhanced as deemed
  32.  * necessary by the community.
  33.  *
  34.  * Mark Hessling                     email: M.Hessling@gu.edu.au
  35.  * 36 David Road                     Phone: +61 7 849 7731
  36.  * Holland Park                      Fax:   +61 7 875 5314
  37.  * QLD 4121
  38.  * Australia
  39.  */
  40.  
  41. /*
  42. $Header: C:\THE\RCS\comm2.c 1.4 1993/09/01 16:25:38 MH Interim MH $
  43. */
  44.  
  45. #include <stdio.h>
  46.  
  47. #include "the.h"
  48. #include "proto.h"
  49.  
  50. /*#define DEBUG 1*/
  51.  
  52. /*-------------------------- external data ----------------------------*/
  53. extern LINE *next_line,*curr_line;
  54. extern VIEW_DETAILS *vd_current,*vd_first,*vd_mark;
  55. extern char current_screen;
  56. extern SCREEN_DETAILS screen[MAX_SCREENS];        /* screen structures */
  57. extern char current_file;         /* pointer to current file */
  58. extern WINDOW *foot,*error_window;
  59. extern bool error_on_screen;
  60. extern char *temp_cmd;
  61. extern char *cmd_rec;
  62. extern unsigned short cmd_rec_len;
  63. extern char *pre_rec;
  64. extern unsigned short pre_rec_len;
  65. extern char *rec;
  66. extern unsigned short rec_len;
  67. extern char mode_insert;        /* defines insert mode toggle */
  68. extern char in_profile;    /* indicates if processing profile */
  69. extern char in_macro;
  70. extern char *tempfilename;
  71. extern unsigned short file_start;
  72. extern char curr_path[MAX_FILE_NAME+1] ;
  73. extern char sp_path[MAX_FILE_NAME+1] ;
  74. extern char sp_fname[MAX_FILE_NAME+1] ;
  75. /*man-start*********************************************************************
  76. COMMAND
  77.      emsg - display error message
  78.  
  79. SYNTAX
  80.      EMSG [message]
  81.  
  82. DESCRIPTION
  83.      The EMSG command displays an error message on the error line.
  84.      This command is usually issued from a macro file.
  85.  
  86. COMPATIBILITY
  87.      XEDIT: Does not support [mmmnnns text] option
  88.      KEDIT: Compatible
  89.  
  90. SEE ALSO
  91.      EMSG
  92.  
  93. STATUS
  94.      Complete.
  95. **man-end**********************************************************************/
  96. #ifdef PROTO
  97. int Emsg(char *params)
  98. #else
  99. int Emsg(params)
  100. char *params;
  101. #endif
  102. /***********************************************************************/
  103. {
  104. /*-------------------------- external data ----------------------------*/
  105. /*--------------------------- local data ------------------------------*/
  106. /*--------------------------- processing ------------------------------*/
  107. #ifdef TRACE
  108.  trace_function("comm1.c:   Emsg");
  109. #endif
  110.  display_error(0,params);
  111. #ifdef TRACE
  112.  trace_return();
  113. #endif
  114.  return(RC_OK);
  115. }
  116. /*man-start*********************************************************************
  117. COMMAND
  118.      enter - execute a command
  119.  
  120. SYNTAX
  121.      ** effective only if bound to a key **
  122.  
  123. DESCRIPTION
  124.      The ENTER command executes the command currently displayed on the
  125.      command line, if the cursor is currently displayed there.
  126.      If the key associated with ENTER is pressed while in the main or
  127.      prefix window, then the cursor will move to the first column of the
  128.      next line. If the mode is currently in 'insert', then a new line
  129.      is added and the cursor placed at the first column of the new line.
  130.  
  131. COMPATIBILITY
  132.      XEDIT: N/A
  133.      KEDIT: N/A
  134.  
  135. STATUS
  136.      Complete.
  137. **man-end**********************************************************************/
  138. #ifdef PROTO
  139. int Enter(char *params)
  140. #else
  141. int Enter(params)
  142. char *params;
  143. #endif
  144. /***********************************************************************/
  145. {
  146. /*--------------------------- local data ------------------------------*/
  147.  unsigned short x,y;
  148.  short rc=RC_OK;
  149.  register int i;
  150.  static char first=TRUE;
  151.  static char number_of_commands=0;
  152.  WINDOW *w;
  153. /*--------------------------- processing ------------------------------*/
  154. #ifdef TRACE
  155.  trace_function("comm1.c:   Enter");
  156. #endif
  157.  switch(CURRENT_VIEW->current_window)
  158.    {
  159.     case WINDOW_COMMAND:
  160.          for (i=0;i<cmd_rec_len;i++)
  161.              temp_cmd[i] = cmd_rec[i];
  162.          temp_cmd[cmd_rec_len] = '\0';
  163.          strtrunc(temp_cmd);
  164.          add_command(temp_cmd);
  165.          rc = command_line(temp_cmd,COMMAND_ONLY_FALSE);
  166.          break;
  167.     case WINDOW_PREFIX:
  168.          Down_arrow((char *)"");
  169.          getyx(CURRENT_WINDOW,y,x);
  170.          wmove(CURRENT_WINDOW,y,0);
  171.          break;
  172.     case WINDOW_MAIN:
  173.                                        /* check for insert mode or not */
  174.          if (mode_insert)
  175.            {
  176.             post_process_line(CURRENT_VIEW->focus_line);
  177.             insert_new_line((char *)"",0,1,get_true_line(),FALSE,FALSE);
  178.            }
  179.          else
  180.            {
  181.             Down_arrow((char *)"");
  182.             getyx(CURRENT_WINDOW,y,x);
  183.             wmove(CURRENT_WINDOW,y,0);
  184.            }
  185.          break;
  186.    }
  187. #ifdef TRACE
  188.  trace_return();
  189. #endif
  190.  return(rc);
  191. }
  192. /*man-start*********************************************************************
  193. COMMAND
  194.      expand - expand tab characters to spaces
  195.  
  196. SYNTAX
  197.      EXPand [target]
  198.  
  199. DESCRIPTION
  200.      The EXPAND command converts all tab characters to spaces depending
  201.      on the size of a tab determined by [SET] TABS command.
  202.  
  203. COMPATIBILITY
  204.      XEDIT: Compatible.
  205.      KEDIT: Compatible.
  206.  
  207. STATUS
  208.      Complete.
  209. **man-end**********************************************************************/
  210. #ifdef PROTO
  211. int Expand(char *params)
  212. #else
  213. int Expand(params)
  214. char *params;
  215. #endif
  216. /***********************************************************************/
  217. {
  218. /*--------------------------- local data ------------------------------*/
  219. #define EXP_PARAMS  1
  220.  char *word[EXP_PARAMS+1];
  221.  char parm[EXP_PARAMS];
  222.  register int i;
  223.  unsigned short num_params;
  224.  long num_lines,true_line;
  225.  unsigned short x,y;
  226.  int direction;
  227.  LINE *curr;
  228. /*--------------------------- processing ------------------------------*/
  229. #ifdef TRACE
  230.  trace_function("comm3.c:   Expand");
  231. #endif
  232. /*---------------------------------------------------------------------*/
  233. /* Validate the parameters that have been supplied.                    */
  234. /* If no parameter is supplied, 1 is assumed.                          */
  235. /*---------------------------------------------------------------------*/
  236.  num_params = param_split(params,word,EXP_PARAMS,WORD_DELIMS,TEMP_PARAM);
  237.  if (num_params == 0)
  238.     {
  239.      num_params = 1;
  240.      word[0] = (char *)"1";
  241.     }
  242.     if (equal((char *)"all",word[0],3))
  243.        true_line = 1L;
  244.     else
  245.        true_line = get_true_line();
  246.  
  247.  if ((num_lines = valid_target(word[0],true_line)) == TARGET_ERROR)
  248.    {
  249.     display_error(4,(char *)word[0]);
  250. #ifdef TRACE
  251.     trace_return();
  252. #endif
  253.     return(RC_INVALID_OPERAND);
  254.    }
  255.  if (num_lines == TARGET_NOT_FOUND)
  256.    {
  257.     display_error(17,(char *)"");
  258. #ifdef TRACE
  259.     trace_return();
  260. #endif
  261.     return(RC_TARGET_NOT_FOUND);
  262.    }
  263. /*---------------------------------------------------------------------*/
  264. /* Determine in which direction we are working.                        */
  265. /*---------------------------------------------------------------------*/
  266.  if (num_lines < 0)
  267.    {
  268.     dir